﻿using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;

namespace OA.Core.Security
{
    /// <summary>
    /// 不可逆加密
    /// </summary>
    public class IrreversibleEncryption
    {
        /// <summary>
        /// SHA1加密字符串
        /// </summary>
        /// <param name="source">源字符串</param>
        /// <returns>加密后的字符串</returns>
        public string SHA1Encryption(string source)
        {
            SHA1 sha1 = SHA1.Create();
            byte[] hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(source));
            return BitConverter.ToString(hash).Replace("-", "").ToLower();             
        }

        /// <summary>
        /// MD5加密字符串
        /// </summary>
        /// <param name="source">源字符串</param>
        /// <returns>加密后的字符串</returns>
        public string MD5Encryption(string source)
        {
            using (var md5 = MD5.Create())
            {
                var result = md5.ComputeHash(Encoding.UTF8.GetBytes(source));
                var strResult = BitConverter.ToString(result);
                return strResult.Replace("-", "").ToUpper();
            }
        }
    }
}
